function goBack() {
    window.location.href ='PagerServlet';
}
function selectAll(event){
    var checkboxes = document.querySelectorAll('input[name="cartCheckBox"]');
    checkboxes.forEach(function(checkbox) {
        checkbox.checked = event.target.checked;
    });
}
/*根据单个复选框的选择情况确定全选复选框是否被选中*/
function selectSingle() {
    var allcheckbox = document.getElementById('allCheckBox');
    var checkboxes = document.querySelectorAll('input[name="cartCheckBox"]');
    // 假设所有复选框都被选中
    var allChecked = true;
    for (let i = 0; i < checkboxes.length; i++) {
        if (!checkboxes[i].checked) {
            // 如果有任何一个复选框未被选中，则将 allChecked 设置为 false 并跳出循环
            allChecked = false;
            break;
        }
    }
    // 如果所有复选框都被选中，则设置全选复选框为选中状态；否则，设置为未选中状态
    allcheckbox.checked = allChecked;
}

addEventListener('load', () => {
    document.querySelectorAll(".table>.tbody").forEach((e, i) => {
        e.addEventListener('scroll', function() {
            // 取得.thead的div
            let thead = this.parentNode.querySelector('.thead');
            // 当.tbody向左滚动时，改变.thead的margin-left，使.thead与.tbody同时向左滚动，形成一体的效果
            thead.style.marginLeft = -this.scrollLeft + 'px';
        })
    })
})
window.onload = function() {
    let move = document.querySelector('.move');
    let heightDiv = document.querySelector('.hegiht');
    let originalBackgroundColor = getComputedStyle(move).backgroundColor;
    let overlay = document.createElement('div');
    overlay.style.position = "absolute";
    overlay.style.top = 0;
    overlay.style.left = 0;
    overlay.style.width = "100%";
    overlay.style.height = "100%";
    overlay.style.backgroundColor = 'transparent';
    overlay.style.pointerEvents = "none";
    move.appendChild(overlay);
    let isDragging = false; // 是否正在拖动
    heightDiv.onmousedown = function(event) {
        isDragging = true; // 鼠标按下时标记为正在拖动
        document.body.style.cursor = "move"; // 设置鼠标指针样式为拖动
        let xStart = event.clientX;
        let yStart = event.clientY;
        overlay.style.backgroundColor = originalBackgroundColor; // 显示覆盖层以隐藏颜色
        let div = move.cloneNode(false);
        div.style.border = "1px dashed #ccc";
        div.style.background = "none"; // 设置克隆体div的背景为透明
        div.style.position = "absolute"; // 将克隆的div设置为绝对定位，避免影响原div的定位
        document.body.appendChild(div);
        let left = parseInt(getComputedStyle(move).left);
        let top = parseInt(getComputedStyle(move).top);
        document.onmousemove = function(event) {
            if (!isDragging) return; // 如果不是拖动状态则不处理
            let xEnd = event.clientX;
            let yEnd = event.clientY;
            let x = xStart - xEnd;
            let y = yStart - yEnd;
            div.style.left = (left - x) + 'px';
            div.style.top = (top - y) + 'px';
        };
        document.onmouseup = function() {
            if (!isDragging) return; // 如果不是拖动状态则不处理
            isDragging = false; // 鼠标抬起时标记为非拖动状态
            document.onmousemove = null;
            document.onmouseup = null;
            overlay.style.backgroundColor = 'transparent'; // 隐藏覆盖层以显示颜色
            document.body.style.cursor = "default"; // 指针恢复为默认样式
            move.style.left = div.style.left;
            move.style.top = div.style.top;
            div.remove();
        };
    };
};
addEventListener('load', () => {
    document.querySelectorAll(".table>.tbody").forEach((e, i) => {
        e.addEventListener('scroll', function() {
            // 取得.thead的div
            let thead = this.parentNode.querySelector('.thead');

            // 当.tbody向左滚动时，改变.thead的margin-left，使.thead与.tbody同时向左滚动，形成一体的效果
            thead.style.marginLeft = -this.scrollLeft + 'px';
        })
    })
})
var fh = document.getElementById("fh");
var move = document.getElementById("move");
var button = document.getElementById("button");
button.addEventListener("click", function() {
    move.style.display = (move.style.display === "block") ? "none" : "block";
});
fh.addEventListener("click", function() {
    move.style.display = (move.style.display === "block") ? "none" : "block";
});
